home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0411.ZIP / DBCOMRAT.C < prev    next >
Text File  |  1985-10-26  |  2KB  |  90 lines

  1. /*
  2.  * Program to read a dBASE program file and count the number of comment and
  3.  * program lines in it.
  4.  */
  5. #include "stdio.h"
  6. #define CR 0xd
  7. #define LF 0xa
  8. #define TB 0x9
  9. #define SP 0x20
  10. #define TRUE 1
  11. #define FALSE 0
  12. main(argc,argv)
  13.     int argc;
  14.     char *argv[];
  15.     {
  16.     float ratio,
  17.       cmcntr,
  18.       lfcntr,
  19.       code;
  20.     int  c,
  21.      outfile,
  22.      infile,
  23.      frstchar;
  24.     if ((argc == 1) || (argv[1][0] == '?'))
  25.     {
  26.     puts("\n");
  27.     puts("Syntax: DBCOMRAT <infile>\n");
  28.     puts("where   infile  is the filespec for the input data\n");
  29.     puts("\n");
  30.     puts("The input file should be a dBASE .PRG file. This file is\n");
  31.     puts("examined for the number of comment lines within it. The ratio\n");
  32.     puts("of comment lines to program lines is output at program end.\n");
  33.     puts("\n");
  34.     exit(0);
  35.     }
  36.     if (argv[1][0] == '#')
  37.     {
  38.     puts("\n");
  39.     puts("PROGRAM: DBCOMRAT\n");
  40.     puts("Author : Peter Townsend\n");
  41.     puts("Date   : 25Oct85\n");
  42.     puts("Version: 1.1\n");
  43.     exit(0);
  44.     }
  45.     if ((infile = open(argv[1],0)) == -1)
  46.     {
  47.     printf("\nCannot open input file %s\n",argv[1]);
  48.     exit(1);
  49.     }
  50.     frstchar = TRUE;
  51.     lfcntr = 0;
  52.     cmcntr = 0;
  53.     while ((c = fgetc(infile)) != EOF)
  54.     {
  55.     if (c == LF)
  56.         {
  57.         lfcntr++;
  58.         frstchar = TRUE;
  59.         }
  60.     else
  61.         {
  62.         if (frstchar)
  63.         {
  64.         if (c == '*')
  65.             {
  66.             cmcntr++;
  67.             frstchar = FALSE;
  68.             }
  69.         else
  70.             {
  71.             if ((c != TB) && (c != SP))
  72.             {
  73.             frstchar = FALSE;
  74.             }
  75.             }
  76.         }
  77.         }
  78.     }
  79.     fclose(infile);
  80.     code = lfcntr - cmcntr;
  81.     ratio = cmcntr/code;
  82.     puts("\n");
  83.     printf("There were  : %6.0f comment lines\n",cmcntr);
  84.     printf("            : %6.0f program lines\n",code);
  85.     printf("            : %6.0f total   lines\n",lfcntr);
  86.     puts("\n");
  87.     printf("The ratio of comment to code lines is %.3f : 1\n",ratio);
  88.     exit(0);
  89.     }
  90.